package com.kzd.btgame.main.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import android.widget.TextView
import com.kzd.btgame.R
import com.kzd.btgame.custom.setOnClickAntiShakeListener
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AlphaConfig
import razerdp.util.animation.AnimationHelper

class SystemTipsPopup(context: Context, val onClick: ((view: View) -> Unit)? = null) :
    BasePopupWindow(context) {

    init {
        popupGravity = Gravity.CENTER
        setOverlayNavigationBar(false)
    }

    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_system_tips)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        contentView.findViewById<TextView>(R.id.tvSystemTipsSure).setOnClickAntiShakeListener {
            dismiss()
            onClick?.invoke(it)
        }
        contentView.findViewById<TextView>(R.id.tvSystemTipsClose).setOnClickAntiShakeListener {
            dismiss()
            onClick?.invoke(it)
        }
    }

    override fun onCreateShowAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.IN)
            .toShow()
    }

    override fun onCreateDismissAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.OUT)
            .toDismiss()
    }

    fun setTitle(title: String): SystemTipsPopup {
        contentView.findViewById<TextView>(R.id.tvSystemTipsTitle)
            .text = title
        return this
    }

    fun setMessage(message: String): SystemTipsPopup {
        contentView.findViewById<TextView>(R.id.tvSystemTipsMessage)
            .text = message
        return this
    }

    fun setVisibleClose(): SystemTipsPopup {
        contentView.findViewById<TextView>(R.id.tvSystemTipsClose)
            .visibility = View.VISIBLE
        contentView.findViewById<View>(R.id.viewSystemTipsLine)
            .visibility = View.VISIBLE
        return this
    }

    fun setButtonText(sure: String, close: String): SystemTipsPopup {
        contentView.findViewById<TextView>(R.id.tvSystemTipsSure)
            .text = sure
        contentView.findViewById<TextView>(R.id.tvSystemTipsClose)
            .text = close
        return this
    }

}